package com.emptyMe.org.controller;

import com.emptyMe.basic.utils.AjaxResult;
import com.emptyMe.org.domain.LoginInfo;
import com.emptyMe.org.domain.LoginInfoDTO;
import com.emptyMe.org.query.LoginInfoQuery;
import com.emptyMe.org.service.ILoginInfoService;
import com.emptyMe.org.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/login")
@Api(tags = "登录接口", description = "登录接口详细api描述")
public class LoginInfoController {

    @Autowired
    private ILoginInfoService service;

    @PostMapping("account")  // account:账户
    @ApiOperation(value = "登录功能实现")
    public AjaxResult login(@RequestBody LoginInfo info) {
        try {
            LoginInfoDTO dto = service.login(info);
//            ArrayList<Map<String,Object>> newlist = service.menuList(info.getId());
//            if (dto.getType()==0) {
            // 管理员
            ArrayList<Map<String, Object>> list = new ArrayList<>();
            HashMap<String, Object> map = new HashMap<>();
            map.put( "path","/dashboard");
            map.put("name", "Dashboard");
            list.add(map);
            map = new HashMap<>();
            map.put( "path","/admin");
            map.put("name", "Admin");

//            ArrayList<Map<String, Object>> list2 = new ArrayList<>();
//            HashMap<String, Object> map2 = new HashMap<>();
//            map2.put("path", "dept");
//            map2.put("name", "Dept");
//            list2.add(map2);
//            map.put("children",list2);
//
            list.add(map);
            dto.setMenuList(list);
            return AjaxResult.me(dto);
//            }
        } catch (Exception e) {
//            e.printStackTrace();
//            return AjaxResult.me(false, "登陆失败"+e.getCause());
            return AjaxResult.me(false, e.getMessage());
        }
    }

    @PostMapping("menuList")  // account:账户
    @ApiOperation(value = "登录功能实现")
    public AjaxResult login(Long id) {
        return service.menuList(id);
    }
}
